home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / gsdll.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-09  |  5.2 KB  |  193 lines

  1. /* Copyright (C) 1989, 1995, 1996 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18. /* Portions Copyright (C) 1994, 1995, 1996, Russell Lang.  All rights reserved. */
  19.  
  20.  
  21. /* gsdll.c */
  22. /* Dynamic Link Library interface for OS/2 and MS-Windows Ghostscript */
  23. /* front end to gs.c */
  24.  
  25. /* HOW MANY OF THESE INCLUDES ARE REALLY NEEDED? */
  26.  
  27. /* Define PROGRAM_NAME before we include std.h */
  28. #define PROGRAM_NAME gs_product
  29. #include "ctype_.h"
  30. #include "memory_.h"
  31. #include <stdarg.h>
  32. #include "string_.h"
  33.  
  34. #include "ghost.h"
  35. #include "gscdefs.h"
  36. #include "gxdevice.h"
  37. #include "gxdevmem.h"
  38. #include "stream.h"
  39. #include "errors.h"
  40. #include "estack.h"
  41. #include "ialloc.h"
  42. #include "ivmspace.h"
  43. #include "sfilter.h"        /* for iscan.h */
  44. #include "ostack.h"        /* must precede iscan.h */
  45. #include "iscan.h"
  46. #include "main.h"
  47. #include "imainarg.h"
  48. #include "store.h"
  49. #include "files.h"                /* requires stream.h */
  50. #include "interp.h"
  51. #ifdef _Windows
  52. #include "windows_.h"
  53. #ifndef __WIN32__
  54. #define GSDLLEXPORT _export
  55. #endif
  56. #else
  57. #define INCL_DOS
  58. #define INCL_WIN
  59. #include <os2.h>
  60. #endif
  61. #include "gsdll.h"        /* header for DLLs */
  62. #include <setjmp.h>
  63.  
  64. jmp_buf gsdll_env;        /* used by gp_do_exit in DLL configurations */
  65.  
  66. private int gsdll_usage;    /* should be needed only for 16-bit SHARED DATA */
  67.  
  68. /****** SINGLE-INSTANCE HACK ******/
  69. private gs_main_instance *gsdll_minst;    /* instance data */
  70. extern HWND hwndtext;        /* in gp_mswin.h */
  71.  
  72. GSDLL_CALLBACK pgsdll_callback;    /* callback for messages and stdio to caller */
  73.  
  74.  
  75. /* ---------- DLL exported functions ---------- */
  76.  
  77. /* arguments are:
  78.  * 1. callback function for stdio and for notification of 
  79.  *   sync_output, output_page and resize events
  80.  * 2. window handle, used as parent.  Use NULL if you have no window.
  81.  * 3. argc
  82.  * 4. argv
  83.  */
  84. int GSDLLAPI 
  85. gsdll_init(GSDLL_CALLBACK callback, HWND hwnd, int argc, char GSFAR *argv[])
  86. {    
  87.     if (gsdll_usage) {
  88.         return GSDLL_INIT_IN_USE;    /* DLL can't be used by multiple programs under Win16 */
  89.     }
  90.     gsdll_usage++;
  91.  
  92.     if (setjmp(gsdll_env)) {
  93.         gsdll_usage--;
  94.         if (gs_exit_status)
  95.             return gs_exit_status;    /* error */
  96.         return GSDLL_INIT_QUIT;    /* not an error */
  97.     }
  98.  
  99.     /****** SINGLE-INSTANCE HACK ******/
  100.     pgsdll_callback = callback;
  101.     hwndtext = hwnd;
  102.  
  103.     /****** SINGLE-INSTANCE HACK ******/
  104.     gsdll_minst = gs_main_instance_default();
  105.  
  106.     /* in gs.c */
  107.     gs_main_init_with_args(gsdll_minst, argc, argv);
  108.  
  109.     return 0;
  110. }
  111.  
  112. /* if return value < 0, then error occured and caller should call */
  113. /* gsdll_exit, then unload library */
  114. int GSDLLAPI
  115. gsdll_execute_begin(void)
  116. {    int exit_code;
  117.     ref error_object;
  118.     int code;
  119.     if (!gsdll_usage)
  120.         return -1;
  121.     if (setjmp(gsdll_env))
  122.         return gs_exit_status;    /* error */
  123.     code = gs_main_run_string_begin(gsdll_minst, 0, &exit_code, &error_object);
  124.     return code;
  125. }
  126.  
  127. /* if return value < 0, then error occured and caller should call */
  128. /* gsdll_execute_end, then gsdll_exit, then unload library */
  129. int GSDLLAPI
  130. gsdll_execute_cont(const char GSFAR *str, int len)
  131. {    int exit_code;
  132.     ref error_object;
  133.     int code;
  134.     if (!gsdll_usage)
  135.         return -1;
  136.     if (setjmp(gsdll_env))
  137.         return gs_exit_status;    /* error */
  138.     code = gs_main_run_string_continue(gsdll_minst, str, len, 0, &exit_code, &error_object);
  139.     if (code == e_NeedInput)
  140.         code = 0;    /* this is not an error */
  141.     return code;
  142. }
  143.  
  144. /* if return value < 0, then error occured and caller should call */
  145. /* gsdll_exit, then unload library */
  146. int GSDLLAPI
  147. gsdll_execute_end(void)
  148. {    int exit_code;
  149.     ref error_object;
  150.     int code;
  151.     if (!gsdll_usage)
  152.         return -1;
  153.     if (setjmp(gsdll_env))
  154.         return gs_exit_status;    /* error */
  155.     code = gs_main_run_string_end(gsdll_minst, 0, &exit_code, &error_object);
  156.     return code;
  157. }
  158.  
  159. int GSDLLAPI
  160. gsdll_exit(void)
  161. {
  162.     if (!gsdll_usage)
  163.         return -1;
  164.     gsdll_usage--;
  165.  
  166.     if (setjmp(gsdll_env))
  167.         return gs_exit_status;    /* error */
  168.     /* don't call gs_exit() since this would cause caller to exit */
  169.     gs_finit(0, 0);
  170.     pgsdll_callback = (GSDLL_CALLBACK)NULL;
  171.     return 0;
  172. }
  173.  
  174. /* return revision numbers and strings of Ghostscript */
  175. /* Used for determining if wrong GSDLL loaded */
  176. /* this may be called before gsdll_init */
  177. int GSDLLAPI
  178. gsdll_revision(char GSFAR **product, char GSFAR **copyright, 
  179.     long GSFAR *revision, long GSFAR *revisiondate)
  180. {
  181.     if (product)
  182.         *product = (char *)gs_product;
  183.     if (copyright)
  184.         *copyright = (char *)gs_copyright;
  185.     if (revision)
  186.         *revision = gs_revision;
  187.     if (revisiondate)
  188.         *revisiondate = gs_revisiondate;
  189.     return 0;
  190. }
  191.  
  192. /* end gsdll.c */
  193.